#设置cmake所需的最小版本
cmake_minimum_required (VERSION 3.12)
project(CHEN)

#设置c++标准
set(CMAKE_CXX_STANDARD 14)

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(ENABLE_CPPCHECK "Enable cppcheck static check" OFF)

message(STATUS "CHEN CMake Info")
message(STATUS "=======================================================")
message(STATUS "    Operation System :  ${CMAKE_SYSTEM}")
message(STATUS "    CPU Architecture : ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "    Build Type : ${CMAKE_BUILD_TYPE}${CMAKE_CONFIGURATION_TYPES}")
message(STATUS "    Shared Library  : ${BUILD_SHARED_LIBS}")
message(STATUS "=======================================================")

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)

set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

include(FetchContent)
FetchContent_Declare(
  googletest
  URL https://github.com/google/googletest/archive/refs/tags/release-1.10.0.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

#FetchContent_MakeAvailable(googletest) #cmake 3.14 above

file (GLOB CHEN_COMMON_SRC_FILE Chen/inc/*.cpp)
file (GLOB CHEN_LOG_SRC_FILE Chen/src/Log/impl/*.cpp)
file (GLOB CHEN_LOG_CONFIG_FILE Chen/src/Config/impl/*.cpp)

include_directories(.)
link_directories(/usr/local/lib)

find_library(YAMLCPP yaml-cpp)

set(${PROJECT_NAME}_COMMON_INCLUDE
    Chen/inc
    Chen/src/Log/inc
    Chen/src/Config/inc
)

set(${PROJECT_NAME}_INCLUDE
    ${CHEN_COMMON_INCLUDE}
)

set(${PROJECT_NAME}_SRCS
    ${CHEN_LOG_SRC_FILE}
    ${CHEN_LOG_CONFIG_FILE}
    ${CHEN_COMMON_SRC_FILE}
)

add_library(CHEN SHARED ${CHEN_SRCS} )
target_include_directories(CHEN PUBLIC ${${PROJECT_NAME}_INCLUDE})

add_executable(test_Log tests/test_Log.cpp)     
target_include_directories(test_Log PUBLIC ${${PROJECT_NAME}_INCLUDE})
target_link_libraries( 
  test_Log 
  CHEN 
  gtest
  ${YAMLCPP}
  pthread
)

add_executable(test_Config tests/test_Config.cpp)     
target_include_directories(test_Config PUBLIC ${${PROJECT_NAME}_INCLUDE})
target_link_libraries( 
  test_Config 
  CHEN 
  gtest
  ${YAMLCPP}
  pthread
)

include(GoogleTest)
#gtest_discover_tests(test_Log)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

